package com.zsk.gen;

import java.io.FileNotFoundException;
import java.io.PrintWriter;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;

public class VelocityTest {

    String basePackge = "com.zsk";
    String moudleName = "test";

    public static void main(String[] args) {
        VelocityEngine ve = new VelocityEngine();
        ve.setProperty("input.encoding", "UTF-8");// 输入编码
        ve.setProperty("output.encoding", "UTF-8");// 输出编码

        // 进行初始化操作
        ve.init();
        // 加载模板，设定模板编码
        Template t = ve.getTemplate("template/test.vm", "utf-8");
        // 设置初始化数据
        VelocityContext context = new VelocityContext();

        context.put("name", "zhangsike");

        // 设置输出
        PrintWriter writer = null;
        try {
            writer = new PrintWriter("template/test-out.java");
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // 将环境数据转化输出
        t.merge(context, writer);
        writer.close();

    }

}
